# -*- coding: utf-8 -*-

import sys
import time
import random
from multiprocessing import Pool

import logging

logger = logging.getLogger(__name__)


def logger_config():
    logger_format = '%(asctime)s.%(msecs)03d %(processName)24s %(funcName)16s %(lineno)3d  %(message)s'
    logging.basicConfig(format=logger_format, datefmt='%H:%M:%S', level=logging.INFO, stream=sys.stdout)
    pass


def func_apply():
    delay = 10 * random.random()
    logger.info('delay:%s', delay)
    time.sleep(delay)
    pass


def py_pool():
    n = 4
    pool = Pool(processes=n)
    for i in range(n):
        pool.apply(func=func_apply, args=())
        pass

    pool.close()
    pool.join()
    logger.info('pool')

    pass


if __name__ == '__main__':
    logger_config()
    py_pool()
    logger.info('main')

    pass
